<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./index.html">
    <style>
        textarea {
            width: 100%;
            height: 200px;
            background-color: #333;
            color: white;
            border: 1px solid rgba(255, 255, 255, 0.2);
            border-radius: 10px;
            padding: 10px;
            font-family: monospace;
            resize: none;
        }
        .save-btn {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            cursor: pointer;
        }
        .save-btn:hover {
            background-color: #45a049;
        }
    </style>
</head>
<body>
    <h3>撰写新文章</h3>
    <textarea id="markdown-editor" placeholder="在这里输入你的Markdown内容..."></textarea>
    <button class="save-btn" onclick="savePost()">保存文章</button>

    <script>
        function savePost() {
            let markdownContent = document.getElementById("markdown-editor").value;
            if (!markdownContent.trim()) {
                alert("请填写文章内容！");
                return;
            }

            // Create a new list item for the post
            let postList = document.getElementById("post-list");
            let newPost = document.createElement("li");
            newPost.innerHTML = `文章 ${postList.children.length + 1}: 新文章`;

            // Make the new post clickable and show the Markdown content on click
            newPost.onclick = function() {
                let contentDiv = document.getElementById("markdown-content");
                contentDiv.innerHTML = marked.parse(markdownContent);
            };

            // Add the new post to the list
            postList.appendChild(newPost);

            // Clear the editor after saving
            document.getElementById("markdown-editor").value = "";
        }
    </script>
</body>
</html>